<?php
if (!defined('IN_WONDERSHARE')){
	die('Hacking attempt');
}

class AuthorModule{

	private $db;
   
	public function __construct(){
		$this->db = $GLOBALS['db'];
	}
	
	//note 取得作者列表
	public function get_list( $uid ){
		$sql = "SELECT * FROM author WHERE uid = '{$uid}'";
		return $this->db->getAll( $sql );	
	}
	
	//note 取得作者列表
	public function get_all_list(){
		$sql = "SELECT aid, author FROM author ORDER BY uid ASC";
		return $this->db->getAll( $sql );	
	}
	
	
	//note 新增作者
	public function add( $uid, $author, $email, $avatar, $gaccount ){
		$sql = "INSERT INTO author SET uid = '{$uid}', author = '{$author}', email = '{$email}', avatar = '{$avatar}', gaccount = '{$gaccount}'";
		return $this->db->query( $sql );
	}
	
	//note 删除
	public function del( $aid ){
		$sql = "DELETE FROM author WHERE aid = '{$aid}'";
		return $this->db->query( $sql );
	}
	
	//note 编辑
	public function update( $aid, $author, $email, $avatar, $gaccount ){
		$sql = "UPDATE author SET author = '{$author}', email = '{$email}', avatar = '{$avatar}', gaccount = '{$gaccount}' WHERE aid = '{$aid}'";
		return $this->db->query( $sql );
	}
	
	//note 取得一条信息
	public function get_one( $aid ){
		$sql = "SELECT * FROM author WHERE aid = '{$aid}'";
		return $this->db->getOneRs( $sql );
	}
	
	//note 根据负责人id取出所有作者
	public function get_all_by_uid( $uid ){
		$sql = "SELECT aid, uid, author FROM author WHERE uid = '{$uid}'";
		return $this->db->getAll( $sql );
	}
	
	
}